package com.hydl.power.controller;

import com.github.pagehelper.PageInfo;
import com.hydl.power.aop.annotation.LogAnnotation;
import com.hydl.power.pojo.*;
import com.hydl.power.service.AlarmSetService;
import com.hydl.power.service.DeviceService;
import com.hydl.power.service.IncomingCabinetService;
import com.hydl.power.service.PowerDataService;
import com.hydl.power.service.impl.PowerDataServiceImpl;
import com.hydl.power.utils.Resp;
import io.micrometer.core.instrument.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.*;

/**
 * @author wxb
 * @date 2020/4/17 18:25
 */
@Api(value = "UserReportController",tags = "用户报告")
@RequestMapping("/report")
@RestController
@CrossOrigin
public class UserReportController {
    @Autowired
    private IncomingCabinetService incomingCabinetService;

    @Autowired
    private PowerDataService powerDataService;





    @ApiOperation("用点安全分析")
    @PostMapping("/getDeviceAlarm")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "项目id" ,defaultValue = "40232328", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "time" ,defaultValue = "2021-03", dataType = "String"),
    })
    public Resp getDeviceAlarm(String projectId,String time){
        List<DeviceAlarm> list = incomingCabinetService.getDeviceAlarm(projectId,time);
        return Resp.success(list);
    }




    @ApiOperation("获取设备使用年份")
    @PostMapping("/getDeviceLifeCycle")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "项目id" ,defaultValue = "40232328", dataType = "String"),
    })
    public Resp getDeviceLifeCycle(String projectId){
        List<CabinetDevice> list = incomingCabinetService.getDeviceLifeCycle(projectId);
        return Resp.success(list);
    }



    @ApiOperation("查询每月电费/电量")
    @PostMapping("/getMonthElectricityBill")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "项目id" ,defaultValue = "40232328", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "year", value = "年份" ,defaultValue = "2021", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "time", value = "时间2021-03" ,defaultValue = "2021-03", dataType = "String"),
    })
    public Resp getProjectMonthElectricityBill(String projectId,String year,String time){
        Map<String, Object>  map = incomingCabinetService.getMonthElectricityBill(projectId, year,time);
        return Resp.success(map);
    }

        @PostMapping("/userReport")
        @ApiOperation(value = "1、用户报告", produces = "application/json")
        @ApiImplicitParams({
                @ApiImplicitParam(paramType = "query", name = "projectId", value = "项目id", required = false, dataType = "String" ,defaultValue = "40232328"),
                @ApiImplicitParam(paramType = "query", name = "projectName", value = "项目名称", required = false, dataType = "String",defaultValue = "中州国际" ),
                @ApiImplicitParam(paramType = "query", name = "startTime", value = "开始时间", required = false, dataType = "String",defaultValue = "2021-02"),
        })
        public Resp userReport(String projectId,String projectName,String startTime) {
                if(projectId == null || projectName == null ){
                    return Resp.result("400","未查询到数据");
                }
            Map<String,Object> map = incomingCabinetService.userReport(projectId,projectName,startTime);
            if(map.isEmpty()){
                return Resp.result("400","未查询到数据",map);
            }
            return Resp.success(map);
        }


    @PostMapping("/linkRelativeRatio")
    @ApiOperation(value = "同比/环比", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "项目id", required = false, dataType = "String" ,defaultValue = "40232328"),
            @ApiImplicitParam(paramType = "query", name = "startTime", value = "开始时间", required = false, dataType = "String",defaultValue = "2021-02"),
    })
    public Resp linkRelativeRatio(String projectId,String startTime) throws ParseException {
        Map list = incomingCabinetService.linkRelativeRatio(projectId, startTime);
        if (list.size() == 0) {
            return Resp.result("400", "未查询到数据", list);
        }
        return Resp.success(list);
    }
/*    @PostMapping("/queryeEveryDayPower")
    @ApiOperation(value = "2.1、日耗电量分析", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "项目id", required = false, dataType = "String" ,defaultValue = "40232328"),
            @ApiImplicitParam(paramType = "query", name = "startTime", value = "开始时间", required = false, dataType = "String",defaultValue = "2021-02-01"),
            @ApiImplicitParam(paramType = "query", name = "endTime", value = "结束时间",dataType = "String",defaultValue = "2021-02-27")
    })
    public Resp queryeEveryDayPower(String projectId,String startTime,String endTime) throws ParseException {
        List list = incomingCabinetService.queryeEveryDayPower(projectId,startTime,endTime);
        if(list.size() == 0 ){
            return Resp.result("400","未查询到数据",list);
        }
        return Resp.success(list);
    }*/

    @PostMapping("/queryePowerPermutation")
    @ApiOperation(value = "2.2、线路能耗排名", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "projectId", required = false, dataType = "String" ,defaultValue = "40232328"),
            @ApiImplicitParam(paramType = "query", name = "startTime", value = "开始时间", required = false, dataType = "String",defaultValue = "2021-02"),
    })
    public Resp queryePowerPermutation(String projectId,String startTime) throws ParseException {
        List list = incomingCabinetService.queryePowerPermutation(projectId,startTime);
        if(list.size() == 0 ){
            return Resp.result("400","未查询到数据",list);
        }
        return Resp.success(list);
    }

    @PostMapping("/queryePowerFactor")
    @ApiOperation(value = "功率因数", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "projectId", required = false, dataType = "String" ,defaultValue = "40232328"),
            @ApiImplicitParam(paramType = "query", name = "startTime", value = "开始时间", required = false, dataType = "String",defaultValue = "2021-02"),
    })
    public Resp queryePowerFactor(String projectId,String startTime) throws ParseException {
        Map list = incomingCabinetService.queryePowerFactor(projectId,startTime);
        if(list.isEmpty() ){
            return Resp.result("400","未查询到数据",list);
        }
        return Resp.success(list);
    }


       @PostMapping("/queryeTransformerPt")
        @ApiOperation(value = "变压器运行情况", produces = "application/json")
        @ApiImplicitParams({
                @ApiImplicitParam(paramType = "query", name = "projectId", value = "projectId", required = false, dataType = "String" ,defaultValue = "40232328"),
                @ApiImplicitParam(paramType = "query", name = "startTime", value = "开始时间", required = false, dataType = "String",defaultValue = "2021-02"),
        })
        public Resp queryeTransformerPt(String projectId,String startTime) throws ParseException {
            List<IncomingCabinet> list = incomingCabinetService.queryeTransformerPt(projectId,startTime);
            if(list.size() == 0 ){
                return Resp.result("400","未查询到数据",list);
            }
            return Resp.success(list);
        }

    @PostMapping("/queryeLoadAnalysis")
    @ApiOperation(value = "变压器分析", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "projectId", required = false, dataType = "String" ,defaultValue = "40232328"),
            @ApiImplicitParam(paramType = "query", name = "startTime", value = "开始时间", required = false, dataType = "String",defaultValue = "2021-02"),
    })
    public Resp queryeLoadAnalysis(String projectId,String startTime) throws ParseException {
        List map = incomingCabinetService.queryeLoadAnalysis(projectId,startTime);
        if(map.isEmpty()){
            return Resp.result("400","未查询到数据",map);
        }
        return Resp.success(map);
    }

    @PostMapping("/queryOrderCount")
    @ApiOperation(value = "告警数量/巡检次数", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "projectId", required = false, dataType = "String" ,defaultValue = "40232328"),
            @ApiImplicitParam(paramType = "query", name = "startTime", value = "开始时间", required = false, dataType = "String",defaultValue = "2021-02-01"),
            @ApiImplicitParam(paramType = "query", name = "endTime", value = "结束时间",dataType = "String",defaultValue = "2021-02-27")
    })
    public Resp queryOrderCount(String projectId,String startTime,String endTime) throws ParseException {
        Map map = incomingCabinetService.queryOrderCount(projectId,startTime,endTime);
        if(map.isEmpty()){
            return Resp.result("400","未查询到数据",map);
        }
        return Resp.success(map);
    }

    @GetMapping("/11111")
    public void test()  {
       powerDataService.insertPowers();
    }

}
